//
// Created by Semir on 2020/5/12.
//

#include <iostream>

using namespace std;

struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    explicit TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

bool PreTravel(TreeNode* pRoot1, TreeNode* pRoot2) {
    if (pRoot1 == nullptr && pRoot2 != nullptr) {
        return false;
    }
    if (pRoot2 == nullptr) {
        return true;
    }
    if (pRoot1->val == pRoot2->val) {
        return PreTravel(pRoot1->left, pRoot2->left) && PreTravel(pRoot1->right, pRoot2->right);
    } else {
        return false;
    }
}

bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2) {
    if (pRoot1 == nullptr || pRoot2 == nullptr) {
        return false;
    }
    if (pRoot1->val == pRoot2->val) {
        if (PreTravel(pRoot1, pRoot2)) {
            return true;
        }
    }
    return HasSubtree(pRoot1->left, pRoot2) || HasSubtree(pRoot1->right, pRoot2);
}

int main() {

    return 0;
}
